//
//  CustomTableViewCell.m
//  豆瓣电影
//
//  Created by dllo on 16/6/23.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "CustomTableViewCell.h"
#import "MovieModel.h"
#import "UIImageView+WebCache.h"

#define kWith self.contentView.frame.size.width
#define kHeight self.contentView.frame.size.height

@interface CustomTableViewCell()

@property (nonatomic, retain) UIImageView *movieImageView;

@property (nonatomic, retain) UILabel *nameLabel;

@property (nonatomic, retain) UIImageView *backImageView;

@end

@implementation CustomTableViewCell

-(void)dealloc
{
    [_backImageView release];
    [_movieImageView release];
    [_nameLabel release];
    [_cellModel release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        
        self.backImageView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"bg_eventlistcell.png"]];
        [self.contentView addSubview:self.backImageView];
        
        self.movieImageView = [[UIImageView alloc]init];
        [self.backImageView addSubview:self.movieImageView];
        
        
        self.nameLabel = [[UILabel alloc]init];
        [self.backImageView addSubview:self.nameLabel];
        
        [self.nameLabel release];
        [self.movieImageView release];
        [self.backImageView release];
    }
    return self;
}


-(void)layoutSubviews
{
    [super layoutSubviews];
    
    self.movieImageView.frame = CGRectMake(10, 5, kWith * 0.3, kHeight - 20);
    
    self.nameLabel.frame = CGRectMake(self.movieImageView.frame.size.width + 40, 30, kWith * 0.5, kHeight * 0.2);
    
    self.backImageView.frame = CGRectMake(0, 5, self.contentView.frame.size.width - 10, self.contentView.frame.size.height - 10);
    
}


-(void)setCellModel:(MovieModel *)cellModel
{
    if (_cellModel != cellModel) {
        [_cellModel release];
        _cellModel = [cellModel retain];
    }
    
    
    NSURL * url = [NSURL URLWithString:cellModel.pic_url];
    [self.movieImageView sd_setImageWithURL:url];
    
    self.nameLabel.text = cellModel.movieName;

}

@end












